package cn.cds.withyou.admin.stores;

import android.support.annotation.NonNull;

import com.squareup.otto.Subscribe;

import cn.cds.withyou.admin.Application;
import cn.cds.withyou.admin.actions.GameActions;
import cn.ljs.android.buses.ActionBus;
import cn.ljs.android.buses.DataBus;
import cn.ljs.android.store.Store;

/**
 * <p> Description: </p>
 * <p/>
 * <p> Copyright: Copyright (c) 2016 </p>
 *
 * @author: Json.Lee
 * @Version: 1.0
 * @CreateTime: 8/5/2016 15:28
 */
public class GameStore extends Store<GameActions> {

    private static GameStore INSTANCE;

    public static GameStore get () {
        if (null == INSTANCE) {
            INSTANCE = new GameStore(Application.getInstance().getActionsBus(), Application.getInstance().getDataBus());
        }
        return INSTANCE;
    }

    protected GameStore(@NonNull ActionBus actionBus, @NonNull DataBus dataBus) {
        super(actionBus, dataBus);
    }

    @Override
    public void onAction(GameActions actions) {
        GameEvent event = new GameEvent();
        switch (actions.getAction()) {
            case GameActions.GAME_ADDED_SUCC:
                event.code = GameEvent.GAME_ADDED_SUCC;
                break;
            case GameActions.GAME_ADDED_FAIL:
                event.code = GameEvent.GAME_ADDED_FAIL;
                break;
            default:
                return;
        }
        mDataBus.dispatch(event);
    }

    @Subscribe
    @Override
    public void onEventMainThread(GameActions actions) {
        super.onEventMainThread(actions);
    }

    public static class GameEvent extends StoreChangeEvent {
        public final static int GAME_ADDED_SUCC = 0x01;
        public final static int GAME_ADDED_FAIL = 0x02;
    }
}
